package com.git.smp.controller;

import java.text.ParseException;
import java.io.IOException;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.activiti.engine.FormService;
import org.activiti.engine.HistoryService;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.apache.catalina.filters.ExpiresFilter.XHttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.git.smp.core.PageRequest;
import com.git.smp.core.ResponseMessage;
import com.git.smp.dao.ApplyAppendixMapper;
import com.git.smp.dao.ApplyFieldMapper;
import com.git.smp.dao.ApplyServerMapper;
import com.git.smp.dao.ApplySystemCallMapper;
import com.git.smp.dao.ApplySystemMapper;
import com.git.smp.dao.EsbSourceMapper;
import com.git.smp.dao.RequireApplyMapper;
import com.git.smp.dao.SmpServiceMapper;
import com.git.smp.entity.ApplyAppendix;
import com.git.smp.entity.ApplyField;
import com.git.smp.entity.ApplyServer;
import com.git.smp.entity.ApplyServerExtend;
import com.git.smp.entity.ApplySystem;
import com.git.smp.entity.ApplySystemCall;
import com.git.smp.entity.EsbSource;
import com.git.smp.entity.RequireApply;
import com.git.smp.entity.RequireApplyDetail;
import com.git.smp.entity.RequireApplyExtend;
import com.git.smp.entity.SmpService;
import com.git.smp.entity.SmpSystemCall;
import com.git.smp.utils.ObjectUtil;
import com.git.smp.entity.Role;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@RestController
@RequestMapping("/source")
public class EsbSourceController {
	
	Logger logger = LoggerFactory.getLogger(EsbSourceController.class);
	
	@Autowired
	EsbSourceMapper esbSourceMapper;

	
	
	/**
	 * 查询核心路由
	 * @param esbSource
	 * @return
	 */
	@RequestMapping("/getproList")
	public ResponseMessage<List<EsbSource>> getproList(@RequestBody EsbSource esbSource) {
		ResponseMessage<List<EsbSource>> responseMessage = new ResponseMessage<List<EsbSource>>();
		responseMessage.setCode("0000");
		responseMessage.setMessage("查询核心路由成功！");
		
		PageHelper.startPage(1, 5);
		List<EsbSource> esbSourceList = esbSourceMapper.getproList(esbSource);
		
		if (esbSourceList == null) {
			responseMessage.setCode("0001");
			responseMessage.setMessage("查询核心路由失败！");
		}
		
		responseMessage.setExtend(esbSourceList);
		logger.info(responseMessage.getMessage()); 
		return responseMessage;
	}
	
	@RequestMapping("/getproListBysourcePath")
	public ResponseMessage<List<EsbSource>> getproListBysourcePath(@RequestBody EsbSource esbSource) {
		ResponseMessage<List<EsbSource>> responseMessage = new ResponseMessage<List<EsbSource>>();
		responseMessage.setCode("0000");
		responseMessage.setMessage("查询核心路由成功！");
		
		PageHelper.startPage(1, 5);
		List<EsbSource> esbSourceList = esbSourceMapper.getproList(esbSource);
		
		if (esbSourceList == null) {
			responseMessage.setCode("0001");
			responseMessage.setMessage("查询核心路由失败！");
		}
		
		responseMessage.setExtend(esbSourceList);
		logger.info(responseMessage.getMessage()); 
		return responseMessage;
	}
	
	
	@RequestMapping("/addEsbSourceInfo")
	public ResponseMessage addEsbSourceInfo(@RequestBody EsbSource esbSource) {
		ResponseMessage<PageInfo<EsbSource>> responseMessage = new ResponseMessage<PageInfo<EsbSource>>();
		responseMessage.setCode("0000");
		responseMessage.setMessage("新增成功！");
		
		Date date = new Date();
		
		esbSource.setCreateTime(date);
		
		try {
			esbSourceMapper.insertSelective(esbSource);
		} catch (Exception e) {
			logger.error("",e);
			responseMessage.setCode("0001");
			responseMessage.setMessage("新增失败！");
		}

		return responseMessage;
	}
	
	
}
